<%@ page contentType="text/html;charset=UTF-8"%>
<%@include file="../../common/sessionValidate.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html lang="UTF-8">
  <head>
    <title>T_function信息维护</title>
    <%@ include file="../../common/meta.jsp"%>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" >
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="X-UA-Compatible" content="IE=9">
	<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <link rel="stylesheet" href="<%=basePath%>css/my-bootstrap.css" media="screen" id="tuserskin">
    <link rel="stylesheet" href="<%=basePath%>js/toastr/toastr.css">
    <link rel="stylesheet" href="<%=basePath%>css/bootstrapValidator.min.css">
    <link rel="stylesheet" href="<%=basePath%>css/font-awesome.min.css">
    <script type="text/javascript" src="<%= basePath %>js/jquery.cookie.js"></script>
  </head>
  <style>
hr {
    margin-top:1px;
    border-bottom: 1px solid #1BBC9B;
}
  </style>
  <body>
  <form class="form-horizontal form-bordered form-row-strippe" name="ffAdd" id="ffAdd" mentod="post" role="form" data-toggle="validator" enctype="multipart/form-data">
  <div class="" style="margin-right:2px;padding-right:1px;">

   <!-------------------------- 面板  start--------------------------------->
	<div class="panel panel-primary" >
	  <div class="panel-heading clearfix"  id="addHeaderDiv">
	  </div>
	  <div class="panel-body">
           <div class="row" >
                <h5>&nbsp;&nbsp;基本信息</h5>
	            <hr>
            	<div class="col-md-6"><!--start 换列-->
                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">所属上级菜单</label>
                            <div class="col-md-9">
                                <select class="form-control" id="parentid" name="parentid">
								</select>
                             </div>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">功能名称</label>
                            <div class="col-md-9">
                                <input id="functname" name="functname" type="text" class="form-control" placeholder="functname" />
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">显示顺序</label>
                            <div class="col-md-9">
                                <input id="showseq" name="showseq" type="text" class="form-control" placeholder="showseq" />
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">状态</label>
                            <div class="col-md-9">
                                <select class="form-control" id="status" name="status">
								  <option value='1'>有效</option>
								  <option value='0'>无效</option>
								</select>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="control-label col-md-3"> url</label>
                            <div class="col-md-9">
                                <input id="url" name="url" type="text" class="form-control" placeholder="url" />
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">图片名称</label>
                             <div class="col-md-9">
                                <input id="pic" name="pic" type="text" class="form-control" placeholder="pic" readonly onclick="selectPics(0)"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">menuid</label>
                            <div class="col-md-9">
                                <input id="memo" name="memo" type="text" class="form-control" placeholder="生成一级菜单时用的href id，如：系统管理菜单" />
                            </div>
                        </div>
                    </div>
                <!--如果输入元素是偶数个元素，在n=size/2?int时输出2列格式；如果元素是奇数个，需要在n=size/2?int时输出2列格式；需要换列，每行最多显示2列-->
                </div><!--end 换列--><!--start 换列-->
                <div class="col-md-6">
                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">所属模块</label>
                            <div class="col-md-9">
                                <select class="form-control" id="systemid" name="systemid">
                                    <option value='yuanquyunying'>园区运营</option>
                                    <option value='zichanguanli'>资产管理</option>
                                    <option value='wuyeguanli'>物业管理</option>
                                    <option value='caiwuguanli'>财务管理</option>
                                    <option value='xitongbangong'>协同办公</option>
                                    <option value='xitongshezhi'>系统设置</option>

                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">功能id</label>
                            <div class="col-md-9">
                                <input id="functid" name="functid" type="text" class="form-control" placeholder="自动生成，无需填写" readonly="true"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">创建人</label>
                            <div class="col-md-9">
                                <input id="createuserid" name="createuserid" type="text" class="form-control" placeholder="createuserid"  readonly="true"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">创建时间</label>
                            <div class="col-md-9">
                                <input id="createtime" name="createtime" type="text" class="form-control" placeholder="createtime"  readonly="true"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">更新人</label>
                            <div class="col-md-9">
                                <input id="lastupdateuserid" name="lastupdateuserid" type="text" class="form-control" placeholder="lastupdateuserid"  readonly="true"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">更新时间</label>
                            <div class="col-md-9">
                                <input id="lastupdatetime" name="lastupdatetime" type="text" class="form-control" placeholder="lastupdatetime"  readonly="true"/>
                            </div>
                        </div>
                    </div>

                    <!-- <div class="col-md-12">
                        <div class="form-group">
                            <label class="control-label col-md-3">功能级别</label>
                            <div class="col-md-9">
                                  <select class="form-control" id="functlevel" name="functlevel" >
								  <option value='1'>一级菜单</option>
								  <option value='2'>二级菜单</option>
								  <option value='3'>三级菜单</option>
								  <option value='4'>四级菜单</option>
								</select>
                            </div>
                        </div>
                    </div> -->
				</div><!--end 换列-->
            </div><!--end row-->
       </div><!--end body-->

	   <div class="modal-footer bg-info " id='buttonDiv'>
	   </div>
    </div>
    <!--------------------------面板 end------------------------------------>

  </div>
  </form>
  	<!----------------------------------- 选择角色层start --------------------------------->
	<div id="selectRolesDiv" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

	    <div class="modal-dialog" style="width:80%;">
	        <div class="modal-content">
	            <div class="modal-header  label-primary" id="addHeaderDiv">
	            	<button type='button' class='close' data-dismiss='modal' aria-hidden='true'>&times;</button>
	            	<i class='icon-filter'></i>&nbsp;流程节点：<span id="nnodeDiv"></span>图片选择
	            </div>
	            <form class="form-horizontal form-bordered form-row-strippe" name="ffAdd1" id="ffAdd1" method="post" >
                <div class="modal-body">
                   <div class="row" >
				 	<table  id="grid" class="table table-condensed table-striped table-bordered table-hover" class="sortable" cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
				     <thead id="grid_head">
				      <tr>

				          <th onclick="sortTableT.sort('grid',0,'String')" colspan=10>图片样式</th>

				      </tr>
				     </thead>
				     <tbody id="grid_body"></tbody>
				    </table>
				   	 <div class="paging-toolbar">
	   		<ul class="pager" style='margin-bottom:5px;' id='grid_paging'></ul>
	   				 </div>
				   </div>
                </div>
                <div class="modal-footer bg-info" id="buttonDiv">
					<button type="button" class=" btn btn-primary btn-sm" name="addSaveButton" id="addSaveButton" onclick='savePics()'>确定</button>
               		<button type="button" class=" btn btn-danger btn-sm" name="gb" onclick='javascript:$("#selectRolesDiv").modal("hide")'>关闭</button>
                </div>
	            </form>
	        </div>
	    </div>
	</div>
	<!--------------------------------- 选择角色层end ------------------------------->
  </body>
</html>

<script src="<%=basePath%>js/bootstrap.min.js"></script>
<!--<script type="text/javascript" src="js/bootstrapValidator.js"></script>-->
<script src="<%=basePath%>js/bootstrap-paginator.min.js"></script>
<script src="<%=basePath%>/js/respond.js"></script>
<script src="<%=basePath%>/js/html5.js"></script>
<script src="<%=basePath%>js/toastr/toastr.js"></script>
<script src="<%=basePath%>js/bootbox.js"></script>
<script src="<%=basePath%>js/jquery.validate.js"></script>
<!-- <script src="<%=basePath%>js/additional-methods.min.js"></script> -->
<script src="<%=basePath%>js/my-jquery-curd.js"></script>
<script src="<%= basePath %>js/tableSortTool.js" ></script>
<script src="<%= basePath %>js/calendar.js" ></script>
<script type="text/javascript">
//新增保存数据
function add() {
	$("#addSaveButton").attr("disabled", true);
	var url = "<%=basePath%>t_function/saveT_function?time="+Math.random();
	var postData = $("#ffAdd").serializeArray();
	//alert(postData);
    $.post(url, postData, function (data) {
    	//var data = $.parseJSON(data);
        if (data.result=="success") {
            //保存成功  1.关闭弹出层，
          	showSuccessTips("恭喜保存成功!", "提示");
          	history.goBack();
        }
        else {
            $("#addSaveButton").removeAttr("disabled");
        	showErrorTips("保存数据失败!", "错误信息：");
        	return false;
        }
    }).error(function () {
        $("#addSaveButton").removeAttr("disabled");
    	showErrorTips("保存数据失败!", "错误信息：");
    });
}

//更新修改数据到后台
function edit(){
	$("#editSaveButton").attr("disabled", true);
	var url = "<%=basePath%>t_function/updateT_function?time="+Math.random();
	myEdit2(url);
}

function savePics(){
	var picname;
	var picnum=document.getElementsByName("batchSelected");
	for( var i=0;i<picnum.length;i++){
		if (picnum[i].checked){
			picname=picnum[i].value;
			document.getElementById("pic").value=picname;
		}
	}
	$("#selectRolesDiv").modal("hide");
}

function selectPics(startIndex){
	$("#grid_body").html("");
	var pageSize = 1000;
	//1、隐藏或者显示
    $("#selectRolesDiv").modal("show");
	var url = "<%=basePath%>t_pic/getAllT_pic?startIndex="+startIndex+"&pageSize="+pageSize+"&time="+Math.random();
	$.getJSON(url, function (data){
	var str="";
 		$.each(data.items, function(i,item){
	 		if(i%10==0){
				str+="<tr><td><input class='checkboxes' name='batchSelected' id='batchSelected' type='radio' value='"+item.name+"'><i class='"+item.name+"' ></i></td>";
 			}
 			else{
				str+="<td><input class='checkboxes' name='batchSelected' id='batchSelected' type='radio' value='"+item.name+"'><i class='"+item.name+"' ></i></td>";
 				if(i%10==9)
 				{
 					str+="</tr>"
 				}
 			}
		});//end each data;
 	$("#grid_body").append(str);
	});//end get json;
}

//初始化页面及校验
$().ready(function(){
	//1、初始化数据显示
	var name = "菜单资源";
	var optype ='<%=request.getParameter("oplx")%>';
	var id='<%=request.getParameter("id")%>';
	//alert("optype="+optype+";id="+id);
	if(optype=='add'){
		$("#ffAdd")[0].reset();/*重置表单*/
	    var basePath="<i class='icon-plus'></i>&nbsp;";
		setHeader2("新增"+name, basePath);//设置addHeaderDiv标题文字及按钮
		setButtonDivAdd2();//设置adddiv的 操作按钮
		//初始化 上级菜单及id的select options；
        var purl = "<%=basePath%>t_function/getAllT_function?functid=0&startIndex=0&pageSize=1000&time="+Math.random();
        $.getJSON(purl, function (data) {
        	$.each(data.items, function(i,item){
        		if(item.functlevel=='0'){
            		$("#parentid").append("<option value='"+item.functid+"'>"+item.functname+"</option>");
        		}else if(item.functlevel=='1'){
            		$("#parentid").append("<option value='"+item.functid+"'>&nbsp;&nbsp;&nbsp;&nbsp;"+item.functname+"</option>");
        		}else if(item.functlevel=='2'){
            		$("#parentid").append("<option value='"+item.functid+"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+item.functname+"</option>");
        		}else{
            		$("#parentid").append("<option value='"+item.functid+"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+item.functname+"</option>");
        		}
        	});//end each
        });
	}else if(optype=='edit'){
		var basePath="<i class='icon-pencil'></i>&nbsp;";
		setHeader2("修改"+name, basePath);//设置addHeaderDiv标题文字及按钮
		setButtonDivEdit2();//设置adddiv的 操作按钮

		//初始化 上级菜单及id的select options；
        var purl = "<%=basePath%>t_function/getAllT_function?functid=0&startIndex=0&pageSize=1000&time="+Math.random();
        $.getJSON(purl, function (data) {
        	$.each(data.items, function(i,item){
        		if(item.functlevel=='0'){
            		$("#parentid").append("<option value='"+item.functid+"'>"+item.functname+"</option>");
        		}else if(item.functlevel=='1'){
            		$("#parentid").append("<option value='"+item.functid+"'>&nbsp;&nbsp;&nbsp;&nbsp;"+item.functname+"</option>");
        		}else if(item.functlevel=='2'){
            		$("#parentid").append("<option value='"+item.functid+"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+item.functname+"</option>");
        		}else{
            		$("#parentid").append("<option value='"+item.functid+"'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+item.functname+"</option>");
        		}
        	});//end each

    		//初始化页面form表单元素值；
    	   	var url = "<%=basePath%>t_function/getT_function?id="+id+"&time="+Math.random();
    	    $.getJSON(url, function (data) {//获取数据，并且自动填充form，自动代码待修改； @todo;
    	    	setValue(data);
        		//设置原来的上级菜单名称及id；必须放在each循环中，否则会异步执行，each还没执行，后面的就执行了，造成数据不会选中；
    	    	$("#parentid").val(data.parentid); //设置选的上级菜单id及名称;
    	        $("#lastupdatetime").val(doZero($("#lastupdatetime").val()));
    	    });
        });

	}else if(optype=='view'){
		var basePath="<i class='icon-eye-open'></i>&nbsp;";//设置addHeaderDiv标题文字及按钮
		setHeader2("查看"+name, basePath);
		setButtonDivView2();//设置adddiv的 操作按钮
	   	var url = "<%=basePath%>t_function/getT_function?id="+id+"&time="+Math.random();
	    $.getJSON(url, function (data) {//获取数据，并且自动填充form，自动代码待修改； @todo;
	    	setValue(data);
		   	var furl = "<%=basePath%>t_function/getT_function?id="+data.parentid+"&time="+Math.random();
		   	$.getJSON(furl, function (fdata) {//获取上级菜单id对应的名称，显示在页面上
		    	$("#parentid").append("<option value='"+fdata.functid+"'>"+fdata.functname+"</option>");
		   	});
		    $("#lastupdatetime").val(doZero($("#lastupdatetime").val()));
	    });

	    formReadOnly('ffAdd');//设置表单不可修改
	}

	//2、校验脚本初始化，start check
	$("#ffAdd").validate({
		submitHandler:function(form){
            //alert($("#opType").val());
            if($("#opType").val()=="add"){
            	add();
            }else if($("#opType").val()=="edit"){
            	edit();
            }
	    },
		rules: {
			functid: {
			    //required: true,
                digits: true,
			    //minlength: 1,
			    maxlength: 22
    		},
			functname: {
			    //required: true,
			    maxlength: 64
    		},
			parentid: {
			    //required: true,
                digits: true,
			    //minlength: 1,
			    maxlength: 22
    		},
			functlevel: {
			    //required: true,
			    maxlength: 1
    		},
			functtype: {
			    //required: true,
			    maxlength: 1
    		},
			status: {
			    //required: true,
			    maxlength: 1
    		},
			memo: {
			    //required: true,
			    maxlength: 128
    		},
			systemid: {
			    //required: true,
			    maxlength: 64
    		},
			ext1: {
			    //required: true,
			    maxlength: 128
    		},
			ext2: {
			    //required: true,
			    maxlength: 256
    		},
			ext3: {
			    //required: true,
			    maxlength: 512
    		},
			createuserid: {
			    //required: true,
			    maxlength: 64
    		},
			createtime: {
			    //required: true,
			    maxlength: 32
    		},
			lastupdateuserid: {
			    //required: true,
			    maxlength: 64
    		},
			lastupdatetime: {
			    //required: true,
			    maxlength: 30
    		},
			showseq: {
			    //required: true,
                digits: true,
			    //minlength: 1,
			    maxlength: 22
    		},
			url: {
			    //required: true,
			    maxlength: 256
    		},
			pic: {
			    //required: true,
			    maxlength: 256
    		}
	    }, //end rules;
	    messages: {
			functid: {
			    //required: "功能id不能为空！",
                digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
			    //minlength: "<font color='red'>最少输入1位！</font>",
			    maxlength: "<font color='red'>功能id最大支持22位，输入的数据已经超过最大长度！</font>"
    		},
			functname: {
			    maxlength: "<font color='red'>功能名称最大支持64位,输入的数据已经超过最大长度！</font>"
    		},
			parentid: {
			    //required: "上级id不能为空！",
                digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
			    //minlength: "<font color='red'>最少输入1位！</font>",
			    maxlength: "<font color='red'>上级id最大支持22位，输入的数据已经超过最大长度！</font>"
    		},
			functlevel: {
			    maxlength: "<font color='red'>功能级别最大支持1位,输入的数据已经超过最大长度！</font>"
    		},
			functtype: {
			    maxlength: "<font color='red'>功能类型最大支持1位,输入的数据已经超过最大长度！</font>"
    		},
			status: {
			    maxlength: "<font color='red'>状态最大支持1位,输入的数据已经超过最大长度！</font>"
    		},
			memo: {
			    maxlength: "<font color='red'>备注最大支持128位,输入的数据已经超过最大长度！</font>"
    		},
			systemid: {
			    maxlength: "<font color='red'>系统id最大支持64位,输入的数据已经超过最大长度！</font>"
    		},
			ext1: {
			    maxlength: "<font color='red'>扩展1最大支持128位,输入的数据已经超过最大长度！</font>"
    		},
			ext2: {
			    maxlength: "<font color='red'>扩展2最大支持256位,输入的数据已经超过最大长度！</font>"
    		},
			ext3: {
			    maxlength: "<font color='red'>扩展3最大支持512位,输入的数据已经超过最大长度！</font>"
    		},
			createuserid: {
			    maxlength: "<font color='red'>创建人最大支持64位,输入的数据已经超过最大长度！</font>"
    		},
			createtime: {
			    maxlength: "<font color='red'>创建时间最大支持32位,输入的数据已经超过最大长度！</font>"
    		},
			lastupdateuserid: {
			    maxlength: "<font color='red'>更新人最大支持64位,输入的数据已经超过最大长度！</font>"
    		},
			lastupdatetime: {
			    maxlength: "<font color='red'>更新时间最大支持11位,输入的数据已经超过最大长度！</font>"
    		},
			showseq: {
			    //required: "显示顺序不能为空！",
                digits: "<font color='red'>请输入数字，不能输入非数字字符！</font>",
			    //minlength: "<font color='red'>最少输入1位！</font>",
			    maxlength: "<font color='red'>显示顺序最大支持22位，输入的数据已经超过最大长度！</font>"
    		},
			url: {
			    maxlength: "<font color='red'> url最大支持256位,输入的数据已经超过最大长度！</font>"
    		},
			pic: {
			    maxlength: "<font color='red'>图片名称最大支持256位,输入的数据已经超过最大长度！</font>"
    		}
	   } //end message;
   	}); //end validate;
}) //end funciton read;
</script>
